package src.com.foreknow.demo7;

import java.util.Scanner;

/**
 * 方法1：添加用户信息
 * 方法2：根据id查询到某一个用户
 * 方法3.根据id删除某一个用户
 * 方法4.修改某个用户信息
 * 方法5.查询所有用户信息
 */

public class UserManager {

      private User[] users;

    public void init(){
        User[] users= new User[5];
    }
    int count;

    public void addUser(User user){
        if (count < 5){
            users[count] = user;
            count++;
            System.out.println("add success");
        }else {
            System.out.println("add error");
        }
    }

    public User getQuery(int id) {
        User user = null;
        for (int i = 0; i < users.length; i++) {
            if (users[i] != null) {
                if (users[i].getId() == id) {
                    user = users[i];
                }
            }
        }
        return user;
    }


    public boolean  delete(int id){
        return false;
    }


    public User update(User user){
        user.setName("abc");
        user.setAge(40);
        return user;
    }


    public User[] all(){
        for (int i = 0;i < users.length;i++){
            System.out.println(users[i]);
        }
        return users;
    }


    public static void main(String[] args) {
        UserManager manager = new UserManager();
        User user = new User();
        user.setName("tom");
        user.setId(1001);
        user.setAge(15);

        User user1 = new User();
        user1.setName("jack");
        user1.setId(1002);
        user1.setAge(18);

        manager.addUser(user);
        manager.addUser(user1);

        User u = manager.getQuery(1002);
//        if (u!=null){
//            System.out.println(u.getId()+"--"+u.getName()+"--"+u.getAge());
//        }
        User new_user = manager.update(u);
        System.out.println("修改成功：" + new_user.getName()+"--"+ new_user.getAge());



    }




}
